<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div class="container">
            <select id="year"></select>年
            <select id="month"></select>月
            <select id="day"></select>日
            <input type="button" value="查看星期" onclick="getWeek()"/>
        </div>
        <script type="text/javascript">
            /**
             * 函数定义
             * 给select元素添加option
             * @param {Object} id HTIM元素id
             * @param {Object} start  开始值(option)
             * @param {Object} end    结束值(option)
             */
                               //形式参数
            function addOption (id,start,end) {
                var sel=document.getElementById(id);
                var html="";
                for(var i=start;i<=end;i++){
                    html+="<option value='"+i+"'>"+i+"</option>";
                }
                sel.innerHTML=html;
            }
            //函数调用     实际参数
            addOption("year",1970,2050);
            addOption("month",1,12);
            addOption("day",1,31);
            function getWeek () {
                var y=document.getElementById("year").value;
                var m=document.getElementById("month").value;
                var d=document.getElementById("day").value;
                console.log(y,m,d);
                var days=(y-1900)*365;
                console.log(days);
                for(var i=1900;i<y;i++){
                    if(i%4==0&&i%100!=0||i%400==0) days++;
                }
                /*switch(m-1){                  
                    case 11:days+=30;
                    case 10:days+=31;
                    case 9:days+=30;
                    case 8:days+=31;
                    case 7:days+=31;
                    case 6:days+=30;
                    case 5:days+=31;
                    case 4:days+=30;
                    case 3:days+=31;
                    case 2:days+=28; if(y%4==0&&y%100!=0||y%400==0) days++;
                    case 1:days+=31;
                }*/
                for(var i=1;i<m;i++){
                    if(i==2){
                        days+=28;
                        if(y%4==0&&y%100!=0||y%400==0) days++;
                    }
                    else if(i==4||i==6||i==9||i==11){
                        days+=30;
                    }
                    else{
                        days+=31;
                    }
                }
                days+=(d-0);
                console.log(days%7)
            }
        </script>
    </body>
</html>

